package com.ty.system;

public class Test {
        public static int maxProfit(int[] prices, int fee) {
            int n = prices.length;
            int[] dp = new int[2];
            dp[0] = 0;
            dp[1] = -prices[0];
            for (int i = 1; i < n; i++) {
                int tmp = dp[0];
                dp[0] = Math.max(dp[0], dp[1] + prices[i] - fee);
                dp[1] = Math.max(dp[1], tmp - prices[i]);
            }
            return dp[0];
        }

    public static void main(String[] args) {
        System.out.println("hello world"+Test.maxProfit(new int[]{1,3,2,8,4,9}, 2));
    }

}
